/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2012/07/12
* File: GraphicsBuffer.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#ifndef GraphicsBuffer_h__
#define GraphicsBuffer_h__

#include "../Core/Core.h"
#include "../Core/Declare.h"

class GraphicsBuffer
{
public:
	class Mapper
	{
		friend class GraphicsBuffer;
	public:
		Mapper(GraphicsBuffer& buffer, BufferAccess ba)
			: _buffer(buffer)
		{
			_data = _buffer._map(ba);
		}
		~Mapper()
		{
			_buffer._unmap();
		}

		template <typename T>
		const T* Pointer() const
		{
			return static_cast<T*>(_data);
		}
		template <typename T>
		T* Pointer()
		{
			return static_cast<T*>(_data);
		}

	private:
		GraphicsBuffer&		_buffer;
		void*				_data;
	};

public:
	GraphicsBuffer(BufferUsage usage, u32 access_hint);
	virtual ~GraphicsBuffer();

	virtual u32 size() const
	{
		return _size_in_byte;
	}

	virtual BufferUsage usage() const
	{
		return _buffer_usage;
	}

	virtual u32 accessHint() const
	{
		return _access_hint;
	}

	virtual void copyToBuffer(const GraphicsBuffer& other) = 0;

	virtual void resize(u32 size_in_byte) = 0;

	virtual void active() = 0;

protected:
	virtual void* _map(BufferAccess ba) = 0;
	virtual void _unmap() = 0;
protected:
	BufferUsage			_buffer_usage;
	u32					_access_hint;
	u32					_size_in_byte;
};
#endif    /* GraphicsBuffer_h__ */